<?php

	include_once("include/config.php");
	include_once("include/auth.lib.php");
	include_once("include/functions.php");

	$filter = '';
	
	$sql = "SELECT a.id, id_palestra, p.nome nome_palestra, cognomenome, categoria, peso, c.desc 
			  FROM atleti a 
			  JOIN palestre p ON (a.id_palestra = p.id)
			  LEFT JOIN categorie c ON (a.categoria = c.id)
             %s 			  
			 ORDER BY cognomenome";
	$result = runSQL(sprintf($sql, $filter));
	$total = mysql_num_rows($result);
	
	$filter = "WHERE categoria = 'BA'";
	$result = runSQL(sprintf($sql, $filter));
	$bambini = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'FA'";
	$result = runSQL(sprintf($sql, $filter));
	$fanciulli = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'RAM'";
	$result = runSQL(sprintf($sql, $filter));
	$ragazziM = mysql_num_rows($result);	


	$filter = "WHERE categoria = 'RAF'";
	$result = runSQL(sprintf($sql, $filter));
	$ragazziF = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAM' AND peso <= 36";
	$result = runSQL(sprintf($sql, $filter));
	$esam36 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAM' AND peso > 36 AND peso <= 40";
	$result = runSQL(sprintf($sql, $filter));
	$esam40 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAM' AND peso > 40 AND peso <= 45";
	$result = runSQL(sprintf($sql, $filter));
	$esam45 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAM' AND peso > 45 AND peso <= 50";
	$result = runSQL(sprintf($sql, $filter));
	$esam50 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAM' AND peso > 50 AND peso <= 55";
	$result = runSQL(sprintf($sql, $filter));
	$esam55 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAM' AND peso > 55 AND peso <= 60";
	$result = runSQL(sprintf($sql, $filter));
	$esam60 = mysql_num_rows($result);	

	$filter = "WHERE categoria = 'ESAM' AND peso > 60";
	$result = runSQL(sprintf($sql, $filter));
	$esam61 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAF' AND peso <= 36";
	$result = runSQL(sprintf($sql, $filter));
	$esaf36 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAF' AND peso > 36 AND peso <= 40";
	$result = runSQL(sprintf($sql, $filter));
	$esaf40 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAF' AND peso > 40 AND peso <= 44";
	$result = runSQL(sprintf($sql, $filter));
	$esaf44 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAF' AND peso > 44 AND peso <= 48";
	$result = runSQL(sprintf($sql, $filter));
	$esaf48 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAF' AND peso > 48 AND peso <= 52";
	$result = runSQL(sprintf($sql, $filter));
	$esaf52 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESAF' AND peso > 52";
	$result = runSQL(sprintf($sql, $filter));
	$esaf53 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBM' AND peso <= 40";
	$result = runSQL(sprintf($sql, $filter));
	$esbm40 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBM' AND peso > 40 AND peso <= 45";
	$result = runSQL(sprintf($sql, $filter));
	$esbm45 = mysql_num_rows($result);	

	$filter = "WHERE categoria = 'ESBM' AND peso > 45 AND peso <= 50";
	$result = runSQL(sprintf($sql, $filter));
	$esbm50 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBM' AND peso > 50 AND peso <= 55";
	$result = runSQL(sprintf($sql, $filter));
	$esbm55 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBM' AND peso > 55 AND peso <= 60";
	$result = runSQL(sprintf($sql, $filter));
	$esbm60 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBM' AND peso > 60 AND peso <= 66";
	$result = runSQL(sprintf($sql, $filter));
	$esbm66 = mysql_num_rows($result);	

	$filter = "WHERE categoria = 'ESBM' AND peso > 66 AND peso <= 73";
	$result = runSQL(sprintf($sql, $filter));
	$esbm73 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBM' AND peso > 73";
	$result = runSQL(sprintf($sql, $filter));
	$esbm74 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBF' AND peso <= 40";
	$result = runSQL(sprintf($sql, $filter));
	$esbf40 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBF' AND peso > 40 AND peso <= 44";
	$result = runSQL(sprintf($sql, $filter));
	$esbf44 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBF' AND peso > 44 AND peso <= 48";
	$result = runSQL(sprintf($sql, $filter));
	$esbf48 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBF' AND peso > 48 AND peso <= 52";
	$result = runSQL(sprintf($sql, $filter));
	$esbf52 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBF' AND peso > 52 AND peso <= 63";
	$result = runSQL(sprintf($sql, $filter));
	$esbf63 = mysql_num_rows($result);	
	
	$filter = "WHERE categoria = 'ESBF' AND peso > 63";
	$result = runSQL(sprintf($sql, $filter));
	$esbf64 = mysql_num_rows($result);	
	
	
?>
<html>

	<body>
		<table style="font-weight: bold">
			<tr>
				<td>Totale Atleti: </td><td><?php echo $total ?></td>
			</tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td></tr>	
			<tr>
				<td>Totale BAMBINI: </td><td><?php echo $bambini ?></td>
			</tr>
			<tr>
				<td>Totale FANCIULLI: </td><td><?php echo $fanciulli ?></td>
			</tr>
			<tr>
				<td>Totale RAGAZZI M: </td><td><?php echo $ragazziM ?></td>
			</tr>
			<tr>
				<td>Totale RAGAZZI F: </td><td><?php echo $ragazziF ?></td>
			</tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td></tr>	
			<tr>
				<td>Totale ES A M 36: </td><td><?php echo $esam36 ?></td>
			</tr>
			
			<tr>
				<td>Totale ES A M 40: </td><td><?php echo $esam40 ?></td>
			</tr>

			<tr>
				<td>Totale ES A M 45: </td><td><?php echo $esam45 ?></td>
			</tr>

			<tr>
				<td>Totale ES A M 50: </td><td><?php echo $esam50 ?></td>
			</tr>

			<tr>
				<td>Totale ES A M 55: </td><td><?php echo $esam55 ?></td>
			</tr>

			<tr>
				<td>Totale ES A M 60: </td><td><?php echo $esam60 ?></td>
			</tr>			

			<tr>
				<td>Totale ES A M +60: </td><td><?php echo $esam61 ?></td>
			</tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td></tr>	
			<tr>
				<td>Totale ES A F 36: </td><td><?php echo $esaf36 ?></td>
			</tr>
			
			<tr>
				<td>Totale ES A F 40: </td><td><?php echo $esaf40 ?></td>
			</tr>

			<tr>
				<td>Totale ES A F 44: </td><td><?php echo $esaf44 ?></td>
			</tr>

			<tr>
				<td>Totale ES A F 48: </td><td><?php echo $esaf48 ?></td>
			</tr>

			<tr>
				<td>Totale ES A F 52: </td><td><?php echo $esaf52 ?></td>
			</tr>

			<tr>
				<td>Totale ES A F +52: </td><td><?php echo $esaf53 ?></td>
			</tr>			
			<tr><td>&nbsp;</td><td>&nbsp;</td></tr>	
			<tr>
				<td>Totale ES B M 40: </td><td><?php echo $esbm40 ?></td>
			</tr>
			
			<tr>
				<td>Totale ES B M 45: </td><td><?php echo $esbm45 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B M 50: </td><td><?php echo $esbm50 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B M 55: </td><td><?php echo $esbm55 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B M 60: </td><td><?php echo $esbm60 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B M 66: </td><td><?php echo $esbm66 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B M 73: </td><td><?php echo $esbm73 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B M +73: </td><td><?php echo $esbm74 ?></td>
			</tr>			
			<tr><td>&nbsp;</td><td>&nbsp;</td></tr>	
			<tr>
				<td>Totale ES B F 40: </td><td><?php echo $esbf40 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B F 44: </td><td><?php echo $esbf44 ?></td>
			</tr>
			
			<tr>
				<td>Totale ES B F 48: </td><td><?php echo $esbf48 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B F 52: </td><td><?php echo $esbf52 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B F 63: </td><td><?php echo $esbf63 ?></td>
			</tr>			
			
			<tr>
				<td>Totale ES B F +63: </td><td><?php echo $esbf64 ?></td>
			</tr>			
			
		</table>
	</body>
</html>